# Current, as of Thursday, May 28, 2020.
# rm(list = ls())
# setwd("~/Dropbox/Base Dropbox/List Experiment Paper (PS)/Conditional Accept/Replication Files (Carmines-Schmidt PS)/All Model Output")
library(foreign)
library(car)
library(readstata13)
library(zeligverse)
library(ggplot2)
# install.packages("stargazer", dependencies = TRUE)
library(stargazer)
library(apsrtable)
#-----
# CCAP 2008 and 2012. 
ccap.2008 = read.dta13("CarminesSchmidtPS-replication-2008.dta", generate.factors = TRUE)
ccap.2012 = read.dta13("CarminesSchmidtPS-replication-2012.dta", generate.factors = TRUE)

# 2008: assignment to ANY of the sensitive-item conditions. 
ccap.2008$sensitive.item = ifelse(ccap.2008$treatment!="Control", "Sensitive-Item", "Control")
table(ccap.2008$sensitive.item)
table(ccap.2008$sensitive.item, ccap.2008$treatment)
# Dichotomous, numeric version of this variable (1 = sensitive-item conditions; 0 = treatment condition).
ccap.2008$sensitive.item.binary = ifelse(ccap.2008$sensitive.item=="Sensitive-Item", 1, 0) 
table(ccap.2008$sensitive.item.binary)
table(ccap.2008$sensitive.item.binary, ccap.2008$treatment)

# AFRICAN AMERICAN or BASELINE conditions, 2008. 
# Drop African Americans from the subsample. 
afroam.experiment.2008 = subset(ccap.2008, treatment=="African Americans" | treatment=="Control")
afroam.experiment.2008 = subset(afroam.experiment.2008, black!=1)
# MUSLIM or BASELINE conditions, 2008. 
muslims.experiment.2008 = subset(ccap.2008, treatment=="Muslims" | treatment=="Control")
# 'GAY OR HOMOSEXUAL' or BASELINE conditions, 2008. 
gays.experiment.2008 = subset(ccap.2008, treatment=="Gays" | treatment=="Control")
# WOMAN or BASELINE conditions, 2008. 
women.experiment.2008 = subset(ccap.2008, treatment=="Women" | treatment=="Control")

# 2012: assignment to ANY of the sensitive-item conditions. 
ccap.2012$sensitive.item = ifelse(ccap.2012$treatment!="Control", "Sensitive-Item", "Control")
table(ccap.2012$sensitive.item)
table(ccap.2012$sensitive.item, ccap.2012$treatment)
# Dichotomous, numeric version of this variable (1 = sensitive-item conditions; 0 = treatment condition).
ccap.2012$sensitive.item.binary = ifelse(ccap.2012$sensitive.item=="Sensitive-Item", 1, 0) 
table(ccap.2012$sensitive.item.binary)
table(ccap.2012$sensitive.item.binary, ccap.2012$treatment)

# AFRICAN AMERICAN or BASELINE conditions, 2012. 
# Drop African Americans from the subsample. 
afroam.experiment.2012 = subset(ccap.2012, treatment=="African Americans" | treatment=="Control")
afroam.experiment.2012 = subset(afroam.experiment.2012, black!=1)
# MUSLIM or BASELINE conditions, 2012. 
muslims.experiment.2012 = subset(ccap.2012, treatment=="Muslims" | treatment=="Control")
# 'GAY OR HOMOSEXUAL' or BASELINE conditions, 2012. 
gays.experiment.2012 = subset(ccap.2012, treatment=="Gays" | treatment=="Control")
# MORMON or BASELINE conditions, 2012. 
mormons.experiment.2012 = subset(ccap.2012, treatment=="Mormons" | treatment=="Control")
#-----
# AFRICAN AMERICAN CANDIDATE, 2008. 

# Full sample. 
model.1 = lm(item_count ~ afroam_binary,
             data = afroam.experiment.2008)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ afroam_binary + pid_7 + ideology + 
               female + white + education + church + rr + obama_favor + 
               interest + income,
             data = afroam.experiment.2008)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ afroam_binary*republican + afroam_binary*democrat,
             data = afroam.experiment.2008)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ afroam_binary*republican + afroam_binary*democrat +
               ideology + female + white + education + church + rr + 
               obama_favor + interest + income,
             data = afroam.experiment.2008)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ afroam_binary*conservative + afroam_binary*liberal,
             data = afroam.experiment.2008)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ afroam_binary*conservative + afroam_binary*liberal +
               pid_7 + female + white + education + church + rr + 
               obama_favor + interest + income,
             data = afroam.experiment.2008)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# GAY-OR-HOMOSEXUAL CANDIDATE, 2008. 

# Full sample. 
model.1 = lm(item_count ~ gays_binary,
             data = gays.experiment.2008)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ gays_binary + pid_7 + ideology + 
               female + white + black + education + church + rr + obama_favor + 
               interest + income,
             data = gays.experiment.2008)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ gays_binary*republican + gays_binary*democrat,
             data = gays.experiment.2008)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ gays_binary*republican + gays_binary*democrat +
               ideology + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = gays.experiment.2008)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ gays_binary*conservative + gays_binary*liberal,
             data = gays.experiment.2008)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ gays_binary*conservative + gays_binary*liberal +
               pid_7 + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = gays.experiment.2008)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# MUSLIM CANDIDATE, 2008. 

# Full sample. 
model.1 = lm(item_count ~ muslim_binary,
             data = muslims.experiment.2008)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ muslim_binary + pid_7 + ideology + 
               female + white + black + education + church + rr + obama_favor + 
               interest + income,
             data = muslims.experiment.2008)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ muslim_binary*republican + muslim_binary*democrat,
             data = muslims.experiment.2008)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ muslim_binary*republican + muslim_binary*democrat +
               ideology + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = muslims.experiment.2008)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ muslim_binary*conservative + muslim_binary*liberal,
             data = muslims.experiment.2008)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ muslim_binary*conservative + muslim_binary*liberal +
               pid_7 + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = muslims.experiment.2008)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# WOMAN CANDIDATE, 2008. 

# Full sample. 
model.1 = lm(item_count ~ female_binary,
             data = women.experiment.2008)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ female_binary + pid_7 + ideology + 
               female + white + black + education + church + rr + obama_favor + 
               interest + income + clinton_favor,
             data = women.experiment.2008)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ female_binary*republican + female_binary*democrat,
             data = women.experiment.2008)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ female_binary*republican + female_binary*democrat +
               ideology + female + white + black + education + church + rr + 
               obama_favor + interest + income + clinton_favor,
             data = women.experiment.2008)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ female_binary*conservative + female_binary*liberal,
             data = women.experiment.2008)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ female_binary*conservative + female_binary*liberal +
               pid_7 + female + white + black + education + church + rr + 
               obama_favor + interest + income + clinton_favor,
             data = women.experiment.2008)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# SENSITIVE ITEMS (POOLED), 2008.

# Full sample. 
model.1 = lm(item_count ~ sensitive.item.binary,
             data = ccap.2008)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ sensitive.item.binary + pid_7 + ideology + 
               female + white + black + education + church + rr + obama_favor + 
               interest + income,
             data = ccap.2008)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ sensitive.item.binary*republican + sensitive.item.binary*democrat,
             data = ccap.2008)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ sensitive.item.binary*republican + sensitive.item.binary*democrat +
               ideology + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = ccap.2008)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ sensitive.item.binary*conservative + sensitive.item.binary*liberal,
             data = ccap.2008)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ sensitive.item.binary*conservative + sensitive.item.binary*liberal +
               pid_7 + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = ccap.2008)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# AFRICAN AMERICAN CANDIDATE, 2012. 

# Full sample. 
model.1 = lm(item_count ~ afroam_binary,
             data = afroam.experiment.2012)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ afroam_binary + pid_7 + ideology + 
               female + white + education + church + rr + obama_favor + 
               interest + income,
             data = afroam.experiment.2012)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ afroam_binary*republican + afroam_binary*democrat,
             data = afroam.experiment.2012)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ afroam_binary*republican + afroam_binary*democrat +
               ideology + female + white + education + church + rr + 
               obama_favor + interest + income,
             data = afroam.experiment.2012)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ afroam_binary*conservative + afroam_binary*liberal,
             data = afroam.experiment.2012)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ afroam_binary*conservative + afroam_binary*liberal +
               pid_7 + female + white + education + church + rr + 
               obama_favor + interest + income,
             data = afroam.experiment.2012)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# GAY-OR-HOMOSEXUAL CANDIDATE, 2012. 

# Full sample. 
model.1 = lm(item_count ~ gays_binary,
             data = gays.experiment.2012)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ gays_binary + pid_7 + ideology + 
               female + white + black + education + church + rr + obama_favor + 
               interest + income,
             data = gays.experiment.2012)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ gays_binary*republican + gays_binary*democrat,
             data = gays.experiment.2012)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ gays_binary*republican + gays_binary*democrat +
               ideology + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = gays.experiment.2012)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ gays_binary*conservative + gays_binary*liberal,
             data = gays.experiment.2012)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ gays_binary*conservative + gays_binary*liberal +
               pid_7 + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = gays.experiment.2012)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# MUSLIM CANDIDATE, 2012. 

# Full sample. 
model.1 = lm(item_count ~ muslim_binary,
             data = muslims.experiment.2012)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ muslim_binary + pid_7 + ideology + 
               female + white + black + education + church + rr + obama_favor + 
               interest + income,
             data = muslims.experiment.2012)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ muslim_binary*republican + muslim_binary*democrat,
             data = muslims.experiment.2012)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ muslim_binary*republican + muslim_binary*democrat +
               ideology + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = muslims.experiment.2012)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ muslim_binary*conservative + muslim_binary*liberal,
             data = muslims.experiment.2012)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ muslim_binary*conservative + muslim_binary*liberal +
               pid_7 + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = muslims.experiment.2012)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# MORMON CANDIDATE, 2012. 

# Full sample. 
model.1 = lm(item_count ~ mormon_binary,
             data = mormons.experiment.2012)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ mormon_binary + pid_7 + ideology + 
               female + white + black + education + church + rr + obama_favor + 
               interest + income + romney_favor,
             data = mormons.experiment.2012)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ mormon_binary*republican + mormon_binary*democrat,
             data = mormons.experiment.2012)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ mormon_binary*republican + mormon_binary*democrat +
               ideology + female + white + black + education + church + rr + 
               obama_favor + interest + income + romney_favor,
             data = mormons.experiment.2012)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ mormon_binary*conservative + mormon_binary*liberal,
             data = mormons.experiment.2012)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ mormon_binary*conservative + mormon_binary*liberal +
               pid_7 + female + white + black + education + church + rr + 
               obama_favor + interest + income + romney_favor,
             data = mormons.experiment.2012)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# SENSITIVE ITEMS (POOLED), 2012.

# Full sample. 
model.1 = lm(item_count ~ sensitive.item.binary,
             data = ccap.2012)
summary(model.1)
# Full sample plus control variables.
model.2 = lm(item_count ~ sensitive.item.binary + pid_7 + ideology + 
               female + white + black + education + church + rr + obama_favor + 
               interest + income,
             data = ccap.2012)
summary(model.2)
# By partisanship.
model.3 = lm(item_count ~ sensitive.item.binary*republican + sensitive.item.binary*democrat,
             data = ccap.2012)
summary(model.3)
# By partisanship plus control variables. 
model.4 = lm(item_count ~ sensitive.item.binary*republican + sensitive.item.binary*democrat +
               ideology + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = ccap.2012)
summary(model.4)
# By ideology.
model.5 = lm(item_count ~ sensitive.item.binary*conservative + sensitive.item.binary*liberal,
             data = ccap.2012)
summary(model.5)
# By ideology plus control variables. 
model.6 = lm(item_count ~ sensitive.item.binary*conservative + sensitive.item.binary*liberal +
               pid_7 + female + white + black + education + church + rr + 
               obama_favor + interest + income,
             data = ccap.2012)
summary(model.6)

# Full sample.
apsrtable(model.1, model.2, stars = "default", coef.rows = 1)
# By partisanship.
apsrtable(model.3, model.4, stars = "default", coef.rows = 1)
# By ideology.
apsrtable(model.5, model.6, stars = "default", coef.rows = 1)
#-----
# Sample sizes, 2008. 

# Party ID, 2008. 
ccap.2008$pid3 = rep(NA, length(ccap.2008$pid_7))
ccap.2008$pid3[ccap.2008$republican==1] = "Republican"
ccap.2008$pid3[ccap.2008$democrat==1] = "Democratic"
ccap.2008$pid3[ccap.2008$republican==0 & ccap.2008$democrat==0] = "Independent (or Unsure)"
table(ccap.2008$pid3, ccap.2008$treatment)
table(ccap.2008$pid3[ccap.2008$black==0], ccap.2008$treatment[ccap.2008$black==0])

# Ideology, 2008. 
ccap.2008$ideo3 = rep(NA, length(ccap.2008$pid_7))
ccap.2008$ideo3[ccap.2008$conservative==1] = "Conservative"
ccap.2008$ideo3[ccap.2008$liberal==1] = "Liberal"
ccap.2008$ideo3[ccap.2008$conservative==0 & ccap.2008$liberal==0] = "Moderate (or Unsure)"
table(ccap.2008$ideo3, ccap.2008$treatment)
table(ccap.2008$ideo3[ccap.2008$black==0], ccap.2008$treatment[ccap.2008$black==0])
#-----
# Sample sizes, 2012. 

# Party ID, 2012. 
ccap.2012$pid3 = rep(NA, length(ccap.2012$pid_7))
ccap.2012$pid3[ccap.2012$republican==1] = "Republican"
ccap.2012$pid3[ccap.2012$democrat==1] = "Democratic"
ccap.2012$pid3[ccap.2012$republican==0 & ccap.2012$democrat==0] = "Independent (or Unsure)"
table(ccap.2012$pid3, ccap.2012$treatment)
table(ccap.2012$pid3[ccap.2012$black==0], ccap.2012$treatment[ccap.2012$black==0])

# Ideology, 2012. 
ccap.2012$ideo3 = rep(NA, length(ccap.2012$pid_7))
ccap.2012$ideo3[ccap.2012$conservative==1] = "Conservative"
ccap.2012$ideo3[ccap.2012$liberal==1] = "Liberal"
ccap.2012$ideo3[ccap.2012$conservative==0 & ccap.2012$liberal==0] = "Moderate (or Unsure)"
table(ccap.2012$ideo3, ccap.2012$treatment)
table(ccap.2012$ideo3[ccap.2012$black==0], ccap.2012$treatment[ccap.2012$black==0])









